package com.bbzn.device.client.service;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import com.aliyuncs.facebody.model.v20191230.*;

/**
 * @Author wulongbo
 * @Date 2022/1/12 9:31
 * @Version 1.0
 */
public class AddFace {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "LTAI4Ftwf8wSXy9jZKr6G6CA", "0borTfaLj14KpFFW4M4eyF7cqbjBsq");
        /** use STS Token
         DefaultProfile profile = DefaultProfile.getProfile(
         "<your-region-id>",           // The region ID
         "<your-access-key-id>",       // The AccessKey ID of the RAM account
         "<your-access-key-secret>",   // The AccessKey Secret of the RAM account
         "<your-sts-token>");          // STS Token
         **/
        IAcsClient client = new DefaultAcsClient(profile);

        AddFaceRequest request = new AddFaceRequest();
        request.setDbName("faceDb");
        request.setImageUrl("https://baba-face.oss-cn-shanghai.aliyuncs.com/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20220111143426.jpg?Expires=1641951482&OSSAccessKeyId=TMP.3KkcWRufBAa5p7wRMyi6pQN9Gf329Rve8eVHQpUnbn7f5pKFsbWvSGxr9yf4qLyrMaB4sMEDp265KF69jicKPeiffdfb31&Signature=dk4PN5gm8CDv7Pltvut7%2FtCbnU4%3D");
        request.setEntityId("programmerFace");
        // 自定义信息。支持字母、数字、标点符号和汉字。不超过512个字符。
        request.setExtraData("吴龙波");
        // 质量分阈值。对新增人脸图片进行质量分析判断，得到的质量分小于该阈值则表示新增人脸图片质量不符合要求，添加失败。取值范围[0.0,100.0]。0.0或空则表示不做质量分判断逻辑。
        request.setQualityScoreThreshold(8.5F);
        try {
            AddFaceResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }

    }
}
